﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using Newtonsoft.Json;

namespace BrightcoveAPI
{
    // <summary>
    // The Rendition object represents one of the dynamic delivery renditions of a video. 
    // For more information, see Using dynamic delivery and Creating videos for dynamic delivery.
    // </summary>    
    public class BCRendition : BCObject
    {
        #region Private Properties
        
        private String _url;
        private int _encodingRate;
        private int _frameHeight;
        private int _frameWidth;
        private long _size;

        #endregion Private Properties

        #region Public Properties

        // <summary>
        // The URL of the rendition file.
        // </summary> 
        public String url { get { return _url; } }

        // <summary>
        // The rendition's encoding rate, in bits per second. 
        // </summary> 
        public int encodingRate { get { return _encodingRate; } }

        // <summary>
        // The rendition's display height, in pixels.
        // </summary> 
        public int frameHeight { get { return _frameHeight; } }

        // <summary>
        // The rendition's display width, in pixels.
        // </summary> 
        public int frameWidth { get { return _frameWidth; } }

        // <summary>
        // The file size of the rendition, in bytes.
        // </summary> 
        public long size { get { return _size; } }

        #endregion Public Properties

        #region Constructor

        public BCRendition(JsonReader reader)
        {
            reader.Read();
            while (reader.TokenType != JsonToken.EndObject)
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    switch (reader.Value.ToString())
                    {
                        case "error":
                            reader.Read();
                            Console.WriteLine(String.Format("Error: {0}", reader.Value));
                            break;

                        case "url":
                            reader.Read();
                            _url = (String)reader.Value;
                            break;

                        case "encodingRate":
                            reader.Read();
                            _encodingRate = (int)reader.Value;
                            break;

                        case "frameHeight":
                            reader.Read();
                            _frameHeight = (int)reader.Value;
                            break;

                        case "frameWidth":
                            reader.Read();
                            _frameWidth = (int)reader.Value;
                            break;

                        case "size":
                            reader.Read();
                            _size = (long)reader.Value;
                            break;

                        default:
                            reader.Read();
                            break;
                    }
                }
                reader.Read();
            }
            reader.Read();
        }

        #endregion Constructor
    }
}
